package com.itheima.ydd.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.ydd.common.BusinessException;
import com.itheima.ydd.entity.User;
import com.itheima.ydd.mapper.UserMapper;
import com.itheima.ydd.service.UserService;
import org.springframework.stereotype.Service;


/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @since 2022-02-18
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Override
    public void remove(String id) {
        LambdaQueryWrapper<User> queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(User::getId,id);
        queryWrapper.eq(User::getStatus,1);
        int count = this.count(queryWrapper);
        if (count>0){
            throw new BusinessException("当前用户启用状态无法删除");
        }
        this.removeById(id);
    }
}
